<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>达内－NetCTOSS</title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script language="javascript" type="text/javascript" src="../js/jquery-1.4.3.js"></script>
        <script language="javascript" type="text/javascript">
        	var isPassWd=false,rPassF=false,rPassS=false,rCheck=false;
        	var realName=true,rPhone=true,rIdcardNo=true,rEmail=true,rAdr=true,rPcode=true,rQq=true;
            //保存成功的提示信息
            function showResult() {
            	if(rCheck){
            		if(!(isPassWd&&rPassF&&rPassS)){
            			showResultDiv(true);
            			$("#save_result_info").text("修改密码信息错误，请检查");
                		window.setTimeout("showResultDiv(false);", 3000);
            			return;
            		}
            	}else if(!realName){
            		showResultDiv(true);
            		$("#save_result_info").text("姓名填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
            		return;
            	}else if(!rPhone){
            		showResultDiv(true);
            		$("#save_result_info").text("电话填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
                	return;
            	}else if(!rIdcardNo){
            		showResultDiv(true);
            		$("#save_result_info").text("推荐人身份证填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
                	return;
            	}else if(!rEmail){
            		showResultDiv(true);
            		$("#save_result_info").text("Email填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
                	return;
            	}else if(!rAdr){
            		showResultDiv(true);
            		$("#save_result_info").text("地址填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
                	return;
            	}else if(!rPcode){
            		showResultDiv(true);
            		$("#save_result_info").text("邮编填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
                	return;
            	}else if(!rQq){
            		showResultDiv(true);
            		$("#save_result_info").text("QQ填写错误，请重新输入");
                	window.setTimeout("showResultDiv(false);", 3000);
                	return;
            	}
                showResultDiv(true);
                window.setTimeout("showResultDiv(false);", 3000);
                document.forms[0].submit();
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }

            //显示修改密码的信息项
            function showPwd(chkObj) {
                if (chkObj.checked){
                    document.getElementById("divPwds").style.display = "block";
                    rCheck = true;
                }else{
                    document.getElementById("divPwds").style.display = "none";
                    rCheck = false;
                }
            }
            $(function(){
            	var idNumber = $("#idcardNo").val();
            	//从身份证中截取生日
            	var year = idNumber.substring(6,10);
            	var month = idNumber.substring(10,12);
            	var day = idNumber.substring(12,14);
            	var birthday = year+"-"+month+"-"+day;
            	document.getElementById("birthday").value = birthday;
	            //姓名
	            $("#realName").blur(function(){
	            	var name = $(this).val();
	            	var reg = /^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$/;
	            	if(!reg.test(name)){
	            		$("#realNameMsg").addClass("error_msg").text("请输入正确的姓名");
	            		realName = false;
	            		return;
	            	}else{
	            		$("#realNameMsg").removeClass("error_msg").text("输入正确");
	            		realName = true;
	            	}
	            });
	            //电话
           		$("#thePhone").blur(function(){
            		var phone = $(this).val();
            		var tel = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
            		var pho = /\d{3}-\d{8}|\d{4}-\d{7}/;
            		if(!tel.test(phone)&&!pho.test(phone)){
            			$("#thePhoneMsg").addClass("error_msg").text("请输入正确的号码");
            			rPhone=false;
            			return;
            		}else{
            			$("#thePhoneMsg").removeClass("error_msg").text("输入正确");
            			rPhone=true;
            		}
            	});
	            //推荐人身份证
	            $.post("findByIdAccount",{"id":($("#recommenderId").val())},function(data){
		            $("#recommenderIdcardNo").val(data.idcardNo);
	            });
	            $("#recommenderIdcardNo").blur(function(){
            		var idcardNo = $(this).val();
            		//校验身份证
            		var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
            		if(idcardNo==null||idcardNo==""){
            			$("#recommenderIdcardNoMsg").removeClass("error_msg").text("正确的身份证号码格式");
            			rIdcardNo=true;
            			return;
            		}
            		if(!reg.test(idcardNo)){
            			$("#recommenderIdcardNoMsg").addClass("error_msg").text("请输入正确的身份证号");
            			rIdcardNo=false;
            			return;
            		}
	            	//根据推荐人身份证查询推荐人数据
            		$.post(
            			"searchAccount",{"idcardNo":idcardNo},function(data){
            				var account = data;
            				if(account == null){
            					$("#recommenderIdcardNoMsg").addClass("error_msg").text("不存在该推荐人，请重新输入！");
            					rIdcardNo=false;
            				}else{
            					$("#recommenderId").val(account.id);
	            				$("#recommenderIdcardNoMsg").removeClass("error_msg").text("输入正确");
	            				rIdcardNo=true;
            				}
            			}
            		);
            	});
            	//Email
            	$("#theEmail").blur(function(){
            		var email = $(this).val();
            		var len = email.length;
            		var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            		if(!reg.test(email)||len>50){
            			if(email==(null||"")){
            				$("#theEmailMsg").removeClass("error_msg").text("50长度以内，合法的Email格式");
            				rEmail=true;
            				return;
            			}
            			$("#theEmailMsg").addClass("error_msg").text("请输入正确的Email地址");
            			rEmail=false;
            			return;
            		}else{
            			$("#theEmailMsg").removeClass("error_msg").text("输入正确");
            			rEmail=true;
            		}
            	});
            	//地址
            	$("#address").blur(function(){
            		var adr = $(this).val();
            		var reg = /^[\u4E00-\u9FA5A-Za-z0-9_-]{1,50}$/;
            		if(!reg.test(adr)){
            			if(adr==(null||"")){
            				$("#addressMsg").removeClass("error_msg").text("50长度以内");
            				rAdr=true;
            				return;
            			}
            			$("#addressMsg").addClass("error_msg").text("地址或输入长度不正确");
            			rAdr=false;
            			return;
            		}else{
            			$("#addressMsg").removeClass("error_msg").text("输入正确");
            			rAdr=true;
            		}
            	});
            	//邮编
            	$("#postcode").blur(function(){
            		var pcode = $(this).val();
            		var reg = /^[1-9]\d{5}$/;
            		if(!reg.test(pcode)){
            			if(pcode==(null||"")){
            				$("#postcodeMsg").removeClass("error_msg").text("6位数字");
            				rPcode=true;
            				return;
            			}
            			$("#postcodeMsg").addClass("error_msg").text("邮政编码不正确");
            			rPcode=false;
            			return;
            		}else{
            			$("#postcodeMsg").removeClass("error_msg").text("输入正确");
            			rPcode=true;
            		}
            	});
            	//QQ
            	$("#qq").blur(function(){
            		var qq = $(this).val();
            		var reg = /^[1-9][0-9]{4,12}$/;
            		if(!reg.test(qq)){
            			if(qq==(null||"")){
            				$("#qqMsg").addClass("error_msg").text("5到13位数字");
            				rQq=true;
            				return;
            			}
            			$("#qqMsg").addClass("error_msg").text("QQ号码不正确");
            			rQq=false;
            			return;
            		}else{
            			$("#qqMsg").removeClass("error_msg").text("输入正确");
            			rQq=true;
            		}
            	});
            	
            	//验证原密码
            	$("#oldPassWd").blur(function(){
            		var oldPassWd = $(this).val();
            		var idcardNo = $("#idcardNo").val();
            		$.post(
            			"searchAccount",{"idcardNo":idcardNo},function(data){
            				var oldRealPassWd = data.loginPassword;
            				if(oldPassWd == oldRealPassWd){
            					isPassWd = true;
            					$("#oldPassWdMsg").removeClass("error_msg").text("输入正确");
            					if($("#passWd").val()==$("#rePassWd").val()&&$("#passWd").val()!=(null||"")&&$("#rePassWd").val()!=(null||"")){
            						$("#passWdMsg").removeClass("error_msg").text("输入正确");
            						$("#rePassWdMsg").removeClass("error_msg").text("输入正确");
            					}
            				}else{
            					isPassWd = false;
            					$("#oldPassWdMsg").addClass("error_msg").text("密码输入错误");
            				}
            			});
            		
            	});
            	//新密码
            	$("#passWd").blur(function(){
            		if(isPassWd == false){
            			$("#passWdMsg").addClass("error_msg").text("原密码输入错误");
            			rPassF=false;
            		}else{
	            		var passWord = $(this).val();
	            		var reg = /^[\w]{1,20}$/;
	            		if(!reg.test(passWord)){
	            			$("#passWdMsg").addClass("error_msg").text("请输入正确的密码");
	            			rPassF=false;
	            			return;
	            		}else{
	            			$("#passWdMsg").removeClass("error_msg").text("输入正确");
	            			rPassF=true;
	            		}
	            		if(passWord != $("#rePassWd").val()){
	            			$("#rePassWdMsg").addClass("error_msg").text("请输入与上面相同的密码");
	            			rPassS=false;
	            		}else if(passWord == $("#rePassWd").val()){
	            			$("#rePassWdMsg").removeClass("error_msg").text("输入正确");
	            			rPassS=true;
	            		}
            		}
            	});
            	//重复新密码
            	$("#rePassWd").blur(function(){
            		if(isPassWd == false){
            			$("#rePassWdMsg").addClass("error_msg").text("原密码输入错误");
            			rPassF=false;
            		}else{
	            		var passW = $("#passWd").val();
	            		var rePassW = $(this).val();
	            		if(passW != rePassW){
	            			$("#rePassWdMsg").addClass("error_msg").text("您输入的密码与上面不同");
	            			rPassS=false;
	            			return;
	            		}else{
	            			if(rePassW!=null&&rePassW!=""){
		            			$("#rePassWdMsg").removeClass("error_msg").text("输入正确");
		            			rPassS=true;
	            			}else{
	            				$("#rePassWdMsg").addClass("error_msg").text("请输入密码");
	            				rPassS=false;
	            			}
	            		}
            		}
            	});
            	
            });
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="#">[退出]</a>            
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="../index/index" class="index_off"></a></li>
                <li><a href="../role/findRole" class="role_off"></a></li>
                <li><a href="../admin/findAdmin" class="admin_off"></a></li>
                <li><a href="../cost/findCost" class="fee_off"></a></li>
                <li><a href="../account/findAccount" class="account_on"></a></li>
                <li><a href="../service/findService" class="service_off"></a></li>
                <li><a href="../bill/findBill" class="bill_off"></a></li>
                <li><a href="../report/findReport" class="report_off"></a></li>
                <li><a href="../user/userInfo" class="information_off"></a></li>
                <li><a href="../user/userModiPwd" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">  
            <!--保存成功或者失败的提示消息-->          
            <div id="save_result_info" class="save_fail">保存失败，旧密码错误！</div>
            <form action="updateAccount" method="post" class="main_form">
                    <!--必填项-->
                    <div class="text_info clearfix"><span>账务账号ID：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.id" cssClass="readonly" readonly="true" ></s:textfield>
                    </div>
                    <div class="text_info clearfix"><span>姓名：</span></div>
                    <div class="input_info">
                    	<s:textfield name="account.realName" id="realName"></s:textfield>
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="realNameMsg">20长度以内的汉字、字母和数字的组合</div>
                    </div>
                    <div class="text_info clearfix"><span>身份证：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.idcardNo" cssClass="readonly" readonly="true" id="idcardNo"></s:textfield>
                    </div>
                    <div class="text_info clearfix"><span>登录账号：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.loginName" cssClass="readonly" readonly="true"></s:textfield>                        
                        <div class="change_pwd">
                            <input id="chkModiPwd" type="checkbox" onclick="showPwd(this);" />
                            <label for="chkModiPwd">修改密码</label>
                        </div>
                    </div>
                    <!--修改密码部分-->
                    <div id="divPwds">
                        <div class="text_info clearfix"><span>旧密码：</span></div>
                        <div class="input_info">
                            <input type="password" id="oldPassWd" />
                            <span class="required">*</span>
                            <div class="validate_msg_long" id="oldPassWdMsg">30长度以内的字母、数字和下划线的组合</div>
                        </div>
                        <div class="text_info clearfix"><span>新密码：</span></div>
                        <div class="input_info">
                            <input type="password" id="passWd" />
                            <span class="required">*</span>
                            <div class="validate_msg_long" id="passWdMsg">30长度以内的字母、数字和下划线的组合</div>
                        </div>
                        <div class="text_info clearfix"><span>重复新密码：</span></div>
                        <div class="input_info">
                            <input type="password" id="rePassWd" />
                            <span class="required">*</span>
                            <div class="validate_msg_long" id="rePassWdMsg">两次密码必须相同</div>
                        </div>  
                    </div>                   
                    <div class="text_info clearfix"><span>电话：</span></div>
                    <div class="input_info">
                        <s:textfield cssClass="width200" name="account.telephone" id="thePhone"></s:textfield>
                        <span class="required">*</span>
                        <div class="validate_msg_medium" id="thePhoneMsg">正确的电话号码格式：手机或固话</div>
                    </div>
                    <div class="text_info clearfix"><span>推荐人身份证号码：</span></div>
                    <div class="input_info">
                    	<s:hidden id="recommenderId" name="account.recommenderId"></s:hidden>
                        <s:textfield id="recommenderIdcardNo"></s:textfield>
                        <div class="validate_msg_long error_msgs" id="recommenderIdcardNoMsg">正确的身份证号码格式</div>
                    </div>
                    <div class="text_info clearfix"><span>生日：</span></div>
                    <div class="input_info">
                        <input type="text" readonly="readonly" class="readonly" id="birthday"/>
                    </div>
                    <div class="text_info clearfix"><span>Email：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.email" cssClass="width200" id="theEmail"></s:textfield>
                        <div class="validate_msg_medium" id="theEmailMsg">50长度以内，合法的 Email 格式</div>
                    </div> 
                    <div class="text_info clearfix"><span>职业：</span></div>
                    <div class="input_info">
                    	<s:select name="account.occupation" list="#{'1':'干部','2':'学生','3':'技术人员','4':'其他'}"></s:select>
                    </div>
                    <div class="text_info clearfix"><span>性别：</span></div>
                    <div class="input_info fee_type">
                    	<s:radio name="account.gender" list="#{'0':'女','1':'男'}" onclick="feeTypeChange(this.value);"></s:radio>
                    </div> 
                    <div class="text_info clearfix"><span>通信地址：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.mailaddress" cssClass="width350" id="address"></s:textfield>
                        <div class="validate_msg_tiny" id="addressMsg">50长度以内</div>
                    </div> 
                    <div class="text_info clearfix"><span>邮编：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.zipcode" id="postcode"></s:textfield>
                        <div class="validate_msg_long" id="postcodeMsg">6位数字</div>
                    </div> 
                    <div class="text_info clearfix"><span>QQ：</span></div>
                    <div class="input_info">
                        <s:textfield name="account.qq" id="qq"></s:textfield>
                        <div class="validate_msg_long" id="qqMsg">5到13位数字</div>
                    </div>                
                    <!--操作按钮-->
                    <div class="button_info clearfix">
                        <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                        <input type="button" value="取消" class="btn_save" onclick="javascript:history.go(-1)"/>
                    </div>
                </form>  
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)加拿大达内IT培训集团公司 </span>
        </div>
    </body>
</html>

